package com.example.emptytest.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.emptytest.R;
import com.example.emptytest.member;

import java.util.List;

//listview适配器
public class memberListAdapter extends ArrayAdapter<member> {
    private int resourceId;
    public memberListAdapter(Context context, int textViewResourceId, List<member> object){
        super(context,textViewResourceId,object);
        resourceId=textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        member member=getItem(position);
        View view;
        ViewHolder viewHolder;
        if(convertView == null) {
            view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
            viewHolder=new ViewHolder();
            viewHolder.STName=(TextView)view.findViewById(R.id.STName);
            viewHolder.STNum=(TextView)view.findViewById(R.id.STNum);
            viewHolder.STCol=(TextView)view.findViewById(R.id.STCol);
            view.setTag(viewHolder);
        }
        else {
            view = convertView;
            viewHolder=(ViewHolder)view.getTag();
        }
//        TextView fruitName=(TextView)view.findViewById(R.id.FruitName);
//        TextView fruitAge=(TextView)view.findViewById(R.id.FruitAge);
//        fruitName.setText(fruit.getName());
//        String age=fruit.getAge()+"";
//        fruitAge.setText(age);
        viewHolder.STName.setText(member.getName());
        viewHolder.STNum.setText(member.getNum());
        viewHolder.STCol.setText(member.getcollege());
        return view;
    }
    class ViewHolder{
        TextView STName;
        TextView STNum;
        TextView STCol;
    }
}

